package leetcode.code0345;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public String reverseVowels(String s) {
		char[] cs = s.toCharArray();
		int l = 0, r = cs.length - 1;
		int len = cs.length >> 1;
		while (l < len) {
			while (l < r && !this.isVowels(cs[l])) {
				l++;
			}
			while (r > l && !this.isVowels(cs[r])) {
				r--;
			}
			if (l < r) {
				char L = cs[l];
				cs[l] = cs[r];
				cs[r] = L;
			}
			l++;
			r--;
		}
		return new String(cs);
	}

	private boolean isVowels(char c) {
		return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O'
				|| c == 'U';
	}

	@Override
	public void debug1() {
		HelpDebug.compare("Marge, let's \"went.\" i awaIt news telegram.",
				this.reverseVowels("Marge, let's \"went.\" I await news telegram."));
		HelpDebug.compare(".,", this.reverseVowels(".,"));
		HelpDebug.compare("leotcede", this.reverseVowels("leetcode"));
	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

		HelpDebug.compare("holle", this.reverseVowels("hello"));
		HelpDebug.compare("Aa", this.reverseVowels("aA"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
